﻿using Ekton_Manage_DomainCore.Aggregate;
using Ekton_Manage_DTO.RequestModels.User;
using Ekton_Manage_IBusiness;
using Ekton_Manage_InfrastructureCore.Common;
using Ekton_Manage_InfrastructureCore.Repositories;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Ekton_Manage_Web.Controllers
{
    /// <summary>
    /// 广告配置
    /// </summary>
    /// 
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize("Permission")]
    public class AdvertController : ControllerBase
    {
        
        private readonly ISelectAdvertList _selectAdvertList;

        public AdvertController(ISelectAdvertList selectAdvertList)
        {   
            _selectAdvertList = selectAdvertList;
        }

        /// <summary>
        /// 查询全部广告
        /// </summary>
        /// 
        [HttpGet]
        public async Task<MessageModel<PageModel<space_configuration>>> GetAdvertList([FromQuery] QueryDataParame query)
        {     
            var result = await _selectAdvertList.QueryAdvertList(query);

            return new MessageModel<PageModel<space_configuration>>
            {
                msg = "数据获取成功",
                response = new PageModel<space_configuration>
                {
                    pageIndex = query.pageIndex,
                    pageCount = Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(result.Item2) / query.pageSize)),
                    dataCount = result.Item2,
                    pageSize = query.pageSize,
                    data = result.Item1
                }
            };
        }

        /// <summary>
        /// 更新广告
        /// </summary>
        /// 
        [HttpPut]
        public async Task<Message> PutAdvertList([FromBody] DtoInsertSpaceConfiguration query)
        {
            return await _selectAdvertList.PutAdvertList(query);
         
        }

        /// <summary>
        /// 添加广告
        /// </summary>
        /// 
        [HttpPost]
        public async Task<Message> PostAdvertList([FromBody] DtoInsertSpaceConfiguration query)
        {
            return await _selectAdvertList.PostAdvertList(query);
            
        }

        /// <summary>
        /// 删除广告
        /// </summary>
        /// 
        [HttpDelete("{id}")]
        public async Task<Message> DeleteAdvertList(int id)
        {
            return await _selectAdvertList.DeleteAdvertList(id);
         
        }
    }
}
